{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Summary Graphs\n",
    "Graphs of data across multiple years sampled weekly."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.display import display, Markdown\n",
    "import snakemd\n",
    "import datetime\n",
    "\n",
    "from garmindb import GarminConnectConfigManager\n",
    "from garmindb.garmindb import GarminSummaryDb, YearsSummary\n",
    "\n",
    "from jupyter_funcs import format_number\n",
    "from graphs import Graph\n",
    "\n",
    "years_to_display = 4\n",
    "days_to_display = (years_to_display * 365)\n",
    "\n",
    "gc_config = GarminConnectConfigManager()\n",
    "db_params_dict = gc_config.get_db_params()\n",
    "garmin_sum_db = GarminSummaryDb(db_params_dict)\n",
    "\n",
    "graph = Graph()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "years_data = []\n",
    "current_year = datetime.date.today().year\n",
    "for year in range(current_year - years_to_display, current_year + 1):\n",
    "    year_data = YearsSummary.get_year(garmin_sum_db, year)\n",
    "    years_data.append([year, format_number(year_data.rhr_avg), format_number(year_data.rhr_min), format_number(year_data.rhr_max),\n",
    "                       format_number(year_data.hr_avg), format_number(year_data.hr_min), format_number(year_data.hr_max)])\n",
    "\n",
    "doc = snakemd.new_doc()\n",
    "doc.add_heading(\"Heart Rate\", 3)\n",
    "doc.add_table(['Year', 'Avg Resting HR', 'Min Resting HR', 'Max Resting HR', 'Avg HR', 'Min HR', 'Max HR'], years_data)\n",
    "display(Markdown(str(doc)))\n",
    "graph.graph_activity('hr', days=days_to_display)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Intensity Minutes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "graph.graph_activity('itime', days=days_to_display)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "years_data = []\n",
    "current_year = datetime.date.today().year\n",
    "for year in range(current_year - years_to_display, current_year + 1):\n",
    "    year_data = YearsSummary.get_year(garmin_sum_db, year)\n",
    "    years_data.append([year, year_data.steps, year_data.steps_goal, format_number((year_data.steps_goal / year_data.steps) * 100.0)])\n",
    "\n",
    "doc = snakemd.new_doc()\n",
    "doc.add_heading(\"Steps\", 3)\n",
    "doc.add_table(['Year', 'Steps', 'Steaps Goal', 'Steps Goal %'], years_data)\n",
    "display(Markdown(str(doc)))\n",
    "graph.graph_activity('steps')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "years_data = []\n",
    "current_year = datetime.date.today().year\n",
    "for year in range(current_year - years_to_display, current_year + 1):\n",
    "    year_data = YearsSummary.get_year(garmin_sum_db, year)\n",
    "    years_data.append([year, format_number(year_data.weight_avg), format_number(year_data.weight_min), format_number(year_data.weight_max)])\n",
    "\n",
    "doc = snakemd.new_doc()\n",
    "doc.add_heading(\"Weight\", 3)\n",
    "doc.add_table(['Year', 'Avg Weight', 'Min Weight', 'Max Weight'], years_data)\n",
    "display(Markdown(str(doc)))\n",
    "graph.graph_activity('weight', days=days_to_display)"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "d4f50e87ad7f9cd136d9d3dcf547b8236ee2585f92d0ab7c53dfb80e44e3fae9"
  },
  "kernelspec": {
   "display_name": "Python 3.9.5 64-bit ('.venv')",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
